<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"
      @keyup.enter.native="getDataList()">
      <el-form-item label="商品名称" prop="status">
        <el-input v-model="queryParams.search.keyword" placeholder="商品名称"></el-input>
      </el-form-item>
      <el-form-item label="选择商户" prop="status">
        <el-select v-model="queryParams.search.agentId" placeholder="选择商户" clearable style="width: 100%">
          <el-option v-for="(i,index) in agentList" :key="index" :label="i.name"
            :value="i.id" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getDataList"></right-toolbar>
    </el-row>
    <el-table :data="dataList" v-loading="loading" style="width: 100%;">

      <el-table-column type="index" label="序号" width="60"></el-table-column>
      <el-table-column prop="goodsName" label="商品名称" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="goodsNormName" label="商品规格名称" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="quantity"  label="数量" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="sellingPrice" label="售价" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="warehousingPrice"  label="入库价格" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="stockHouseName" label="仓库" align="center" :show-overflow-tooltip="true" />
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getDataList" />
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>
<script>
  import {
    page,
  } from "@/api/business/stock/stock";

  import {
    page as getAgent
  } from "@/api/business/franchiseeinfo";
  import AddOrUpdate from './addOrUpdate'
import { mapState } from 'vuex';
  export default {
    computed:{
      ...mapState({
          sysUser: state => state.user.sysUser,
        })
    },
    data() {
      return {
        activeName: '1',
        info: {},
        driverList: [],
        agentList:[],
        loading: true,
        loading2: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        // 总条数
        total: 0,
        //表格数据
        dataList: [],
        // 弹出层标题
        title: "",
        // 表单参数
        // 显示搜索条件
        showSearch: true,
        form: {},
        // 日期范围
        dateRange: [],
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          search: {
            keyword: '',
          }
        },
        dataList: [],
        rules: {},
        addOrUpdateVisible: false,
        orderList: [],
        comerecordList: [],
        dataDate: []
      }
    },
    components: {
      AddOrUpdate
    },
    created() {
      this.getDataList();
      this.initPage();
    },
    methods: {
      selectAgent(e){
        console.log(e);
        this.queryParams.search.stockHouseId = e;
        page(this.queryParams).then(response => {
          this.dataList = response.data.list;
          this.total = parseInt(response.data.total);
          this.loading = false;
        }).catch(res => {
          this.loading = false
        });
      },
      initPage() {
        getAgent( {
          pageNum: 1,
          pageSize: 100,
          search: {}}).then(res=>{
          this.agentList = res.data.list;
          console.log('agent',res)
        })
      },
      // 获取数据列表
      getDataList() {
        this.loading = true;
        this.queryParams.search.stockHouseId = this.sysUser.agentId

        page(this.queryParams).then(response => {
          this.dataList = response.data.list;
          this.total = parseInt(response.data.total);
          this.loading = false;
        }).catch(res => {
          this.loading = false
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getDataList();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.userId);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.addOrUpdateVisible = true;
        this.title = "添加";
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init({})
        })
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.addOrUpdateVisible = true;
        this.title = "修改";
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(row)
        })
      },

      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          search: {
            keyword: '',
            franchiseeId: ''
          }
        };
        this.getDataList()
      }
    }
  }
</script>
<style lang="scss" scoped>
  .driver_data {
    position: relative;

    .date {
      position: absolute;
      top: 0;
      right: 0;
      z-index: 1;
    }
  }
</style>
